package leetcode.D300.T225;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @File Info: leetcode -- <MyStack>
 * @Author: DYZ
 * @Create: 2022-02-18 17:00:30
 */

class MyStack {

    Deque<Integer> dq = new LinkedList<>();
    int topElement = 0;

    public MyStack() {
    }

    public void push(int x) {
        topElement = x;
        dq.offer(x);
    }

    public int pop() {
        for(int i=0; i<dq.size()-1; i++) {
            topElement = dq.poll();
            dq.offer(topElement);
        }
        int x = dq.poll();
        return x;
    }

    public int top() {
        return topElement;
    }

    public boolean empty() {
        return dq.isEmpty();
    }
}
